/*
 * @Author: SeonHu
 * @Date: 2025-09-16 14:44:19
 * @LastEditors: SeonHu
 * @LastEditTime: 2025-09-23 14:53:45
 * @FilePath: \bg-vben\src\api\authorization\admin\function\index.ts
 * @Description:
 * Copyright © 2020-2025 SANQING Corporation, All rights reserved.
 */
import type { FunctionInputDto, FunctionOutputDto } from './model';

import type { TreeNode } from '#/node';
import type { ErrorMessageMode, PageData } from '#/request';

import { request } from '@/utils/request/axios';

import { PageRequest } from '#/request';

/** 管理-功能信息枚举 */
enum Api {
  /** 读取功能信息 */
  Read = '/api/admin/function/read',
  /** 读取功能[模块]树数据 */
  ReadTreeNode = '/api/admin/function/readTreeNode',

  /** 更新功能信息 */
  Update = '/api/admin/function/update',
}

// #region 读取功能信息
/**
 * 读取功能信息
 * @param params 分页请求
 * @param mode 错误消息模型
 */
export function readFunctions(params: PageRequest, mode: ErrorMessageMode = 'message') {
  return request.post<PageData<FunctionOutputDto>>(
    {
      url: Api.Read,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 读取功能[模块]树数据
/**
 * 读取功能[模块]树数据
 * @param moduleId 模块编号
 * @param mode 错误消息模型
 */
export function readFunctionTreeNodes(moduleId: bigint | string, mode: ErrorMessageMode = 'message') {
  return request.get<TreeNode[]>(
    {
      url: Api.ReadTreeNode,
      params: { moduleId },
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion

// #region 更新功能信息
/**
 * 更新功能信息
 * @param dtos 功能信息
 * @param mode 错误消息模型
 */
export function updateFunctions(dtos: FunctionInputDto[], mode: ErrorMessageMode = 'message') {
  return request.post(
    {
      url: Api.Update,
      params: dtos,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
